﻿#include "entity.h"

GuideEntity::GuideEntity()
{
  
}

GuideEntity::~GuideEntity()
{
}

void GuideEntity::init(int* argc, char **argv)
{
  arguments = new osg::ArgumentParser(argc,argv);
  viewer = new osgQOpenGLWidget;
  connect(viewer, &osgQOpenGLWidget::initialized, this, &GuideEntity::onViewerInitialized);
}

void GuideEntity::onViewerInitialized()
{
  // 设置相机

  osg::ref_ptr<osgGA::KeySwitchMatrixManipulator> keyswitchManipulator = new osgGA::KeySwitchMatrixManipulator;
  keyswitchManipulator->addMatrixManipulator('1', "Trackball", new osgGA::TrackballManipulator());
  keyswitchManipulator->addMatrixManipulator('2', "Flight", new osgGA::FlightManipulator());
  keyswitchManipulator->addMatrixManipulator('3', "Drive", new osgGA::DriveManipulator());
  keyswitchManipulator->addMatrixManipulator('4', "Terrain", new osgGA::TerrainManipulator());
  keyswitchManipulator->addMatrixManipulator('5', "Orbit", new osgGA::OrbitManipulator());
  keyswitchManipulator->addMatrixManipulator('6', "FirstPerson", new osgGA::FirstPersonManipulator());
  keyswitchManipulator->addMatrixManipulator('7', "Spherical", new osgGA::SphericalManipulator());
  viewer->getOsgViewer()->setCameraManipulator(keyswitchManipulator.get());

  // add the state manipulator
  viewer->getOsgViewer()->addEventHandler(new osgGA::StateSetManipulator(viewer->getOsgViewer()->getCamera()->getOrCreateStateSet()));

  // add the thread model handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::ThreadingHandler);

  // add the window size toggle handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::WindowSizeHandler);

  // add the stats handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::StatsHandler);

  // add the help handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::HelpHandler(arguments->getApplicationUsage()));

  // add the record camera path handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::RecordCameraPathHandler);

  // add the LOD Scale handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::LODScaleHandler);

  // add the screen capture handler
  viewer->getOsgViewer()->addEventHandler(new osgViewer::ScreenCaptureHandler);
}
